

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/deng-2022/blog_2/img/fluid.png">
  <link rel="icon" href="/deng-2022/blog_2/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="🍜 打造高效开发环境，善用 IntelliJ IDEA 的实用技巧，探索Java开发利器与编程基石">
<meta property="og:type" content="article">
<meta property="og:title" content="打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化">
<meta property="og:url" content="https://atomgit.com/deng-2022/blog_2/2023/07/06/%E6%89%93%E9%80%A0%E6%B5%81%E7%95%85%E7%BC%96%E7%A0%81%E4%B9%8B%E6%97%85%EF%BC%9AIntelliJ%20IDEA%20%E7%9A%84%E9%AB%98%E6%95%88%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%E4%B8%8E%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="🍜 打造高效开发环境，善用 IntelliJ IDEA 的实用技巧，探索Java开发利器与编程基石">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://atomgit.com/deng-2022/blog_2/img/artical/girl7.jpg">
<meta property="article:published_time" content="2023-07-06T09:56:20.000Z">
<meta property="article:modified_time" content="2024-05-13T06:53:22.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="IDEA">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://atomgit.com/deng-2022/blog_2/img/artical/girl7.jpg">
  
  
  
  <title>打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/deng-2022/blog_2/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/deng-2022/blog_2/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/deng-2022/blog_2/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"atomgit.com","root":"/deng-2022/blog_2/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/deng-2022/blog_2/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/deng-2022/blog_2/js/utils.js" ></script>
  <script  src="/deng-2022/blog_2/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/deng-2022/blog_2/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/deng-2022/blog_2/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/deng-2022/blog_2/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-07-06 17:56" pubdate>
          2023年7月6日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          17k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          44 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="IDEA"
        id="heading-798db05b7c8ac4e09724fd2a87a785a6" role="tab" data-toggle="collapse" href="#collapse-798db05b7c8ac4e09724fd2a87a785a6"
        aria-expanded="true"
      >
        IDEA
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-798db05b7c8ac4e09724fd2a87a785a6"
           role="tabpanel" aria-labelledby="heading-798db05b7c8ac4e09724fd2a87a785a6">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/deng-2022/blog_2/2023/07/06/%E6%89%93%E9%80%A0%E6%B5%81%E7%95%85%E7%BC%96%E7%A0%81%E4%B9%8B%E6%97%85%EF%BC%9AIntelliJ%20IDEA%20%E7%9A%84%E9%AB%98%E6%95%88%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%E4%B8%8E%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E4%BC%98%E5%8C%96/" title="打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：19 天前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="破冰"><a href="#破冰" class="headerlink" title="破冰"></a>破冰</h1><p>🍖 IntelliJ IDEA：一个不可或缺的利器</p>
<ul>
<li>提升开发效率的利器：IntelliJ IDEA在Java开发领域的重要性</li>
</ul>
<ul>
<li>探索功能和特性：深入探索IntelliJ IDEA的强大功能和特性</li>
</ul>
<ul>
<li><p>打造流畅编码之旅：分享实用技巧和优化工作流程的方法</p>
</li>
<li><p>从新手到高手的成长之路：为读者提供宝贵经验和指导</p>
</li>
</ul>
<ul>
<li>从基础到高级：从配置和设置开始，逐步介绍常用功能和高级技巧</li>
</ul>
<ul>
<li>启程进入IntelliJ IDEA世界：探索其中的奇妙与无穷可能</li>
</ul>
<ul>
<li>适用于初学者和经验丰富的开发者：为你打开高效编码的大门</li>
</ul>
<ul>
<li>享受Java开发的旅程：让我们一同探索这个编程基石的奥妙</li>
</ul>
<h2 id="推荐阅读"><a href="#推荐阅读" class="headerlink" title="推荐阅读"></a>推荐阅读</h2><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/javaScript1997/article/details/127987452">【尚硅谷】IDEA2022快速上手开发利器_java2022idea怎么使用-CSDN博客</a></p>
<p>两年前自定义过的 Java 代码模板：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240531180852935.png" alt="image-20240531180852935"></p>
<h1 id="思维碰撞"><a href="#思维碰撞" class="headerlink" title="思维碰撞"></a>思维碰撞</h1><h2 id="使用技巧"><a href="#使用技巧" class="headerlink" title="使用技巧"></a>使用技巧</h2><blockquote>
<p>2024年5月13日</p>
</blockquote>
<p>下载最新版本 IDEA，2023版本的，激活。</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_50737119/article/details/135628513">IDEA2023的激活与安装（全网最靠谱，最快捷的方式）_idea激活-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://www.ajihuo.com/idea/5937.html">IDEA激活码,IDEA激活码2022,IDEA永久激活码_IDEA激活码2022和2023IDEA激活码,IDEA激活码2022,IDEA激活码2023,IDEA注册码,IDEA永久破解,Pycharm激活码,Webstorm激活码 (ajihuo.com)</a></p>
<h2 id=""><a href="#" class="headerlink" title=""></a><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240513233303562.png" alt="image-20240513233303562"></h2><p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240513234203923.png" alt="image-20240513234203923"></p>
<h3 id="常用快捷键"><a href="#常用快捷键" class="headerlink" title="常用快捷键"></a>常用快捷键</h3><ul>
<li><h5 id="Ctrl-S：保存"><a href="#Ctrl-S：保存" class="headerlink" title="Ctrl + S：保存"></a>Ctrl + S：保存</h5></li>
<li><h5 id="Ctrl-A：全选"><a href="#Ctrl-A：全选" class="headerlink" title="Ctrl + A：全选"></a>Ctrl + A：全选</h5></li>
<li><h5 id="Ctrl-F：当前页面搜索"><a href="#Ctrl-F：当前页面搜索" class="headerlink" title="Ctrl + F：当前页面搜索"></a>Ctrl + F：当前页面搜索</h5></li>
<li><h5 id="Ctrl-Shift-R-双击shift：全局搜索"><a href="#Ctrl-Shift-R-双击shift：全局搜索" class="headerlink" title="Ctrl + Shift + R  / 双击shift：全局搜索"></a>Ctrl + Shift + R  / 双击shift：全局搜索</h5></li>
</ul>
<h3 id="多端口启动项目"><a href="#多端口启动项目" class="headerlink" title="多端口启动项目"></a>多端口启动项目</h3><ul>
<li><h5 id="在使用IDEA作Java-Spring全家桶框架后端开发时，经常要多端口跑项目，那么借助IDEA，这种操作怎样实现呢？"><a href="#在使用IDEA作Java-Spring全家桶框架后端开发时，经常要多端口跑项目，那么借助IDEA，这种操作怎样实现呢？" class="headerlink" title="在使用IDEA作Java + Spring全家桶框架后端开发时，经常要多端口跑项目，那么借助IDEA，这种操作怎样实现呢？"></a>在使用IDEA作Java + Spring全家桶框架后端开发时，经常要多端口跑项目，那么借助IDEA，这种操作怎样实现呢？</h5></li>
<li><h5 id="最近在学习SpringCloud微服务，就拿其中一个微服务来演示吧"><a href="#最近在学习SpringCloud微服务，就拿其中一个微服务来演示吧" class="headerlink" title="最近在学习SpringCloud微服务，就拿其中一个微服务来演示吧"></a>最近在学习SpringCloud微服务，就拿其中一个微服务来演示吧</h5></li>
<li><h5 id="首先，运行UserService服务："><a href="#首先，运行UserService服务：" class="headerlink" title="首先，运行UserService服务："></a>首先，运行UserService服务：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230715150128360.png" alt="image-20230715150128360"></p>
<ul>
<li><h5 id="如上图所示，该服务已在8099端口运行"><a href="#如上图所示，该服务已在8099端口运行" class="headerlink" title="如上图所示，该服务已在8099端口运行"></a>如上图所示，该服务已在8099端口运行</h5></li>
<li><h5 id="接下来我们就要实现多端口运行UserService服务了"><a href="#接下来我们就要实现多端口运行UserService服务了" class="headerlink" title="接下来我们就要实现多端口运行UserService服务了"></a>接下来我们就要实现多端口运行UserService服务了</h5></li>
<li><h5 id="复制一份UserService服务运行实例："><a href="#复制一份UserService服务运行实例：" class="headerlink" title="复制一份UserService服务运行实例："></a>复制一份UserService服务运行实例：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230715150352424.png" alt="image-20230715150352424" style="zoom:150%;" />

<ul>
<li><h5 id="在弹窗中指定服务名称，并配置启动端口号："><a href="#在弹窗中指定服务名称，并配置启动端口号：" class="headerlink" title="在弹窗中指定服务名称，并配置启动端口号："></a>在弹窗中指定服务名称，并配置启动端口号：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230715150618730.png" alt="image-20230715150618730"></p>
<figure class="highlight elm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs elm">-<span class="hljs-type">Dserver</span>.<span class="hljs-keyword">port</span>=7099<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="点击确认，在-Not-Started下-即可找到复制后的服务："><a href="#点击确认，在-Not-Started下-即可找到复制后的服务：" class="headerlink" title="点击确认，在 Not Started下 即可找到复制后的服务："></a>点击确认，在 Not Started下 即可找到复制后的服务：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230715150755974.png" alt="image-20230715150755974"></p>
<ul>
<li><h5 id="启动该服务，即可看到-User在7099端口成功运行了："><a href="#启动该服务，即可看到-User在7099端口成功运行了：" class="headerlink" title="启动该服务，即可看到 User在7099端口成功运行了："></a>启动该服务，即可看到 User在7099端口成功运行了：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230715150951551.png" alt="image-20230715150951551"></p>
<ul>
<li><h5 id="这就是IDEA工具中多端口运行服务的方法"><a href="#这就是IDEA工具中多端口运行服务的方法" class="headerlink" title="这就是IDEA工具中多端口运行服务的方法"></a>这就是IDEA工具中多端口运行服务的方法</h5></li>
</ul>
<h3 id="SpringBoot版本与JDK版本不兼容"><a href="#SpringBoot版本与JDK版本不兼容" class="headerlink" title="SpringBoot版本与JDK版本不兼容"></a>SpringBoot版本与JDK版本不兼容</h3><ul>
<li><h5 id="今天新构建了一个新的SpringBoot项目模板，启动项目时报错："><a href="#今天新构建了一个新的SpringBoot项目模板，启动项目时报错：" class="headerlink" title="今天新构建了一个新的SpringBoot项目模板，启动项目时报错："></a>今天新构建了一个新的SpringBoot项目模板，启动项目时报错：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230728224936670.png" alt="image-20230728224936670"></p>
<ul>
<li><h5 id="该项目使用的SpringBoot版本为3-1-2，JDK版本为11，"><a href="#该项目使用的SpringBoot版本为3-1-2，JDK版本为11，" class="headerlink" title="该项目使用的SpringBoot版本为3.1.2，JDK版本为11，"></a>该项目使用的SpringBoot版本为3.1.2，JDK版本为11，</h5></li>
<li><h5 id="在将SpringBoot版本降为2-7-9后，项目启动成功了（2023-07-28晚）"><a href="#在将SpringBoot版本降为2-7-9后，项目启动成功了（2023-07-28晚）" class="headerlink" title="在将SpringBoot版本降为2.7.9后，项目启动成功了（2023/07/28晚）"></a>在将SpringBoot版本降为2.7.9后，项目启动成功了（2023/07/28晚）</h5></li>
</ul>
<h3 id="模拟浏览器发送请求"><a href="#模拟浏览器发送请求" class="headerlink" title="模拟浏览器发送请求"></a>模拟浏览器发送请求</h3><ul>
<li><h5 id="我们在开发过程中，在后台编写好模拟简单的接口后，总是要在网页上输入对应url，测试该接口能否跑通"><a href="#我们在开发过程中，在后台编写好模拟简单的接口后，总是要在网页上输入对应url，测试该接口能否跑通" class="headerlink" title="我们在开发过程中，在后台编写好模拟简单的接口后，总是要在网页上输入对应url，测试该接口能否跑通"></a>我们在开发过程中，在后台编写好模拟简单的接口后，总是要在网页上输入对应url，测试该接口能否跑通</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230729000307955.png" alt="image-20230729000307955"></p>
<ul>
<li><h5 id="然而-IDEA给我们提供了模拟网页请求的功能：（2023-07-28晚）"><a href="#然而-IDEA给我们提供了模拟网页请求的功能：（2023-07-28晚）" class="headerlink" title="然而 IDEA给我们提供了模拟网页请求的功能：（2023/07/28晚）"></a>然而 IDEA给我们提供了模拟网页请求的功能：（2023/07/28晚）</h5></li>
<li><p>如图所示：</p>
</li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230814114805240.png" alt="image-20230814114805240"></p>
<ul>
<li><h5 id="在该页面下，我们可以快速编写HTTP请求，POST或GET："><a href="#在该页面下，我们可以快速编写HTTP请求，POST或GET：" class="headerlink" title="在该页面下，我们可以快速编写HTTP请求，POST或GET："></a>在该页面下，我们可以快速编写HTTP请求，POST或GET：</h5></li>
</ul>
<figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs http">GET http://localhost:80/api/item?id=99<br><span class="hljs-attribute">Accept</span><span class="hljs-punctuation">: </span>application/json<br><br>POST http://localhost:80/api/item<br><span class="hljs-attribute">Content-Type</span><span class="hljs-punctuation">: </span>application/x-www-form-urlencoded<br><br>id=99&amp;content=new-element<br><br>###<br>POST http://localhost:80/api/item<br><span class="hljs-attribute">Content-Type</span><span class="hljs-punctuation">: </span>application/json<br><br>&#123;&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="有关如何正确处理HTTP请求中的参数的问题，日后会更新（2023-08-14午）"><a href="#有关如何正确处理HTTP请求中的参数的问题，日后会更新（2023-08-14午）" class="headerlink" title="有关如何正确处理HTTP请求中的参数的问题，日后会更新（2023/08/14午）"></a>有关如何正确处理HTTP请求中的参数的问题，日后会更新（2023/08/14午）</h5></li>
<li><h5 id="这部分内容👆已经在《SpringBoot-配置》中的-SpringMVC-栏目下完成了（2023-10-05晚）"><a href="#这部分内容👆已经在《SpringBoot-配置》中的-SpringMVC-栏目下完成了（2023-10-05晚）" class="headerlink" title="这部分内容👆已经在《SpringBoot 配置》中的 SpringMVC 栏目下完成了（2023/10/05晚）"></a>这部分内容👆已经在《SpringBoot 配置》中的 SpringMVC 栏目下完成了（2023/10/05晚）</h5></li>
<li><h5 id="不仅如此，我们还可以在编写完成controller层接口后，模拟浏览器发送请求，快速测试："><a href="#不仅如此，我们还可以在编写完成controller层接口后，模拟浏览器发送请求，快速测试：" class="headerlink" title="不仅如此，我们还可以在编写完成controller层接口后，模拟浏览器发送请求，快速测试："></a>不仅如此，我们还可以在编写完成controller层接口后，模拟浏览器发送请求，快速测试：</h5></li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230814122848595.png" alt="image-20230814122848595"></p>
<ul>
<li><h5 id="这部分的实际运用，可以在《快速启动：开发自己的定制化-Spring-Boot-项目模板》一文中的-快速编写Controller层-栏目中了解到（2023-08-14午）"><a href="#这部分的实际运用，可以在《快速启动：开发自己的定制化-Spring-Boot-项目模板》一文中的-快速编写Controller层-栏目中了解到（2023-08-14午）" class="headerlink" title="这部分的实际运用，可以在《快速启动：开发自己的定制化-Spring-Boot-项目模板》一文中的 快速编写Controller层 栏目中了解到（2023/08/14午）"></a>这部分的实际运用，可以在《快速启动：开发自己的定制化-Spring-Boot-项目模板》一文中的 快速编写Controller层 栏目中了解到（2023/08/14午）</h5></li>
</ul>
<h3 id="快速新建demo"><a href="#快速新建demo" class="headerlink" title="快速新建demo"></a>快速新建demo</h3><ul>
<li><p>如何使用IDEA快速新建一个demo，测试简单的代码？</p>
</li>
<li><p>相信长时间依赖Maven快速构建Spring Boot项目，已经对这种构建简单的项目有些生疏了</p>
</li>
<li><h5 id="使用IDEA构建demo的流程如下：（2023-08-14早）"><a href="#使用IDEA构建demo的流程如下：（2023-08-14早）" class="headerlink" title="使用IDEA构建demo的流程如下：（2023/08/14早）"></a>使用IDEA构建demo的流程如下：（2023/08/14早）</h5><ul>
<li>新建Project</li>
<li>新建空项目</li>
</ul>
</li>
<li><p>如图所示：</p>
</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230814105219120.png" alt="image-20230814105219120"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230814105457520.png" alt="image-20230814105457520"></p>
<ul>
<li><p>这里👆新建空项目就行，清爽</p>
</li>
<li><h5 id="如果有遇到不能新建java文件的问题，在对应包右键菜单中如此操作："><a href="#如果有遇到不能新建java文件的问题，在对应包右键菜单中如此操作：" class="headerlink" title="如果有遇到不能新建java文件的问题，在对应包右键菜单中如此操作："></a>如果有遇到不能新建java文件的问题，在对应包右键菜单中如此操作：</h5><ul>
<li>Mark Directory as</li>
<li>Sourse Root</li>
</ul>
</li>
<li><h5 id="依次执行完这两步操作，就可以正常新增java文件了（2023-08-14早）"><a href="#依次执行完这两步操作，就可以正常新增java文件了（2023-08-14早）" class="headerlink" title="依次执行完这两步操作，就可以正常新增java文件了（2023/08/14早）"></a>依次执行完这两步操作，就可以正常新增java文件了（2023/08/14早）</h5></li>
<li><p>详细操作可以看这篇博客：<a target="_blank" rel="noopener" href="https://blog.csdn.net/wukunyan777/article/details/128660908">idea不能建java文件的解决方法_idea无法新建java文件_和小九的岁岁年年的博客-CSDN博客</a></p>
</li>
</ul>
<h3 id="快速构建-Spring-Boot-项目"><a href="#快速构建-Spring-Boot-项目" class="headerlink" title="快速构建 Spring Boot 项目"></a>快速构建 Spring Boot 项目</h3><ul>
<li>随着 <code>JDK 21</code> 的发布，IDEA 中的构建 Spring Boot 项目也发生了变化：</li>
<li>现在构建新项目，可以看到可选的 JDK 版本只有两个：<code>JDK 17</code> 和 <code>JDK 21</code>：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231216115258616.png" alt="image-20231216115258616"></p>
<ul>
<li>由于可选的 <code>Spring Boot</code> 版本只有 <code>3.x.x</code> 版本，且 <code>Spring Boot 3</code> 明确宣布只支持 <code>JDK 17</code> 及以上的版本<strong>（2023/12/16午）</strong></li>
<li>所以新项目如果需要和之前低版本的 <code>Spring Boot</code> 项目合作，就会报错：<strong>不支持发行的 17 版本</strong></li>
<li>这就需要我们更旧项目的 <code>JDK</code> 版本了：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231216115138405.png" alt="image-20231216115138405"></p>
<h3 id="导入模块"><a href="#导入模块" class="headerlink" title="导入模块"></a>导入模块</h3><ul>
<li><h5 id="在IDEA中，如何在一个项目中导入一个模块？（2023-08-14早）"><a href="#在IDEA中，如何在一个项目中导入一个模块？（2023-08-14早）" class="headerlink" title="在IDEA中，如何在一个项目中导入一个模块？（2023/08/14早）"></a>在IDEA中，如何在一个项目中导入一个模块？（2023/08/14早）</h5></li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230814115941831.png" alt="image-20230814115941831"></p>
<ul>
<li><h5 id="选择要导入的模块后，会弹出选项，选择第一个："><a href="#选择要导入的模块后，会弹出选项，选择第一个：" class="headerlink" title="选择要导入的模块后，会弹出选项，选择第一个："></a>选择要导入的模块后，会弹出选项，选择第一个：</h5></li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230814120251967.png" alt="image-20230814120251967"></p>
<ul>
<li><h5 id="没有特殊要求，无脑next就可以了，模块导入成功（2023-08-14早）"><a href="#没有特殊要求，无脑next就可以了，模块导入成功（2023-08-14早）" class="headerlink" title="没有特殊要求，无脑next就可以了，模块导入成功（2023/08/14早）"></a>没有特殊要求，无脑next就可以了，模块导入成功（2023/08/14早）</h5></li>
<li><p>详细步骤可以参考这篇博客：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_48290779/article/details/129758653">如何在IDEA中导入一个模块_idea导入模块_驱动男孩的博客-CSDN博客</a></p>
</li>
</ul>
<h3 id="定时任务实现"><a href="#定时任务实现" class="headerlink" title="定时任务实现"></a>定时任务实现</h3><ul>
<li><p>思来想去，这个栏目还是写在这儿比较合适，介绍一下在Java中，如何写一个<strong>定时任务</strong></p>
</li>
<li><h5 id="推荐阅读：我终于会写-Java-的定时任务了！-掘金-juejin-cn"><a href="#推荐阅读：我终于会写-Java-的定时任务了！-掘金-juejin-cn" class="headerlink" title="推荐阅读：我终于会写 Java 的定时任务了！ - 掘金 (juejin.cn)"></a>推荐阅读：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7158851405531316254">我终于会写 Java 的定时任务了！ - 掘金 (juejin.cn)</a></h5></li>
</ul>
<h4 id="纯手写单线程循环"><a href="#纯手写单线程循环" class="headerlink" title="纯手写单线程循环"></a>纯手写单线程循环</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">timer1</span><span class="hljs-params">()</span> &#123;<br>     <span class="hljs-keyword">new</span> <span class="hljs-title class_">Thread</span>(() -&gt; &#123;<br>         <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) &#123;<br>             System.out.println(<span class="hljs-string">&quot;定时任务A 当前时间: &quot;</span> + LocalDateTime.now());<br>             <span class="hljs-keyword">try</span> &#123;<br>                 Thread.sleep(<span class="hljs-number">1000</span>);<br>             &#125; <span class="hljs-keyword">catch</span> (InterruptedException e) &#123;<br>                 <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">RuntimeException</span>(e);<br>             &#125;<br>         &#125;<br>     &#125;).start();<br> &#125;<br></code></pre></td></tr></table></figure>

<h4 id="Timer和他的小伙伴"><a href="#Timer和他的小伙伴" class="headerlink" title="Timer和他的小伙伴"></a>Timer和他的小伙伴</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">timer2</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-comment">// 单线程</span><br>        <span class="hljs-type">Timer</span> <span class="hljs-variable">timer</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Timer</span>();<br>        System.out.println(<span class="hljs-string">&quot;1秒后执行任务A，A完成后，等待1秒开始定时执行任务B，当前时间: &quot;</span> + LocalDateTime.now());<br>        <span class="hljs-comment">// 1秒后执行</span><br>        timer.schedule(<span class="hljs-keyword">new</span> <span class="hljs-title class_">TimerTask</span>() &#123;<br>            <span class="hljs-meta">@Override</span><br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">run</span><span class="hljs-params">()</span> &#123;<br>                System.out.println(<span class="hljs-string">&quot;定时任务A 当前时间: &quot;</span> + LocalDateTime.now());<br>            &#125;<br>        &#125;, <span class="hljs-number">1000</span>); <span class="hljs-comment">// 这里 1000，就是代表延迟 1000 毫秒后再执行</span><br><br>        <span class="hljs-comment">// 每隔2秒执行一次这个任务</span><br>        timer.schedule(<span class="hljs-keyword">new</span> <span class="hljs-title class_">TimerTask</span>() &#123;<br>            <span class="hljs-meta">@Override</span><br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">run</span><span class="hljs-params">()</span> &#123;<br>                System.out.println(<span class="hljs-string">&quot;定时任务B 当前时间: &quot;</span> + LocalDateTime.now());<br>            &#125;<br>        &#125;, <span class="hljs-number">1000</span>, <span class="hljs-number">2000</span>); <span class="hljs-comment">// 1000 同理，2000 即执行完本次任务后，隔 2000 毫秒后再一次执行，达到定时任务的效果</span><br>    &#125;<br></code></pre></td></tr></table></figure>

<h4 id="ScheduledExecutorService"><a href="#ScheduledExecutorService" class="headerlink" title="ScheduledExecutorService"></a>ScheduledExecutorService</h4><ul>
<li><h5 id="定时执行"><a href="#定时执行" class="headerlink" title="定时执行"></a>定时执行</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">timer4</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-type">ScheduledExecutorService</span> <span class="hljs-variable">scheduledExecutorService</span> <span class="hljs-operator">=</span> Executors.newSingleThreadScheduledExecutor();<br>        System.out.println(<span class="hljs-string">&quot;2秒后开始执行任务，此刻时间---&quot;</span> + LocalDateTime.now());<br>        <span class="hljs-comment">// 固定频率（每隔5秒）开始执行一个任务</span><br>        scheduledExecutorService.scheduleAtFixedRate(() -&gt; &#123;<br>            System.out.println(<span class="hljs-string">&quot;任务开始---&quot;</span> + LocalDateTime.now());<br>            <span class="hljs-keyword">try</span> &#123;<br>                Thread.sleep(<span class="hljs-number">2000</span>);<br>            &#125; <span class="hljs-keyword">catch</span> (InterruptedException e) &#123;<br>                e.printStackTrace();<br>            &#125;<br>            System.out.println(<span class="hljs-string">&quot;任务结束---&quot;</span> + LocalDateTime.now());<br>        &#125;, <span class="hljs-number">2000</span>, <span class="hljs-number">5000</span>, TimeUnit.MILLISECONDS);<br>    &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="延时执行"><a href="#延时执行" class="headerlink" title="延时执行"></a>延时执行</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">timer5</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-type">ScheduledExecutorService</span> <span class="hljs-variable">scheduledExecutorService</span> <span class="hljs-operator">=</span> Executors.newSingleThreadScheduledExecutor();<br>        System.out.println(<span class="hljs-string">&quot;2秒后开始执行任务，此刻时间---&quot;</span> + LocalDateTime.now());<br>        <span class="hljs-comment">// 任务完成后间隔4秒开始执行下一次任务</span><br>        scheduledExecutorService.scheduleWithFixedDelay(() -&gt; &#123;<br>            System.out.println(<span class="hljs-string">&quot;任务开始---&quot;</span> + LocalDateTime.now());<br>            <span class="hljs-keyword">try</span> &#123;<br>                Thread.sleep(<span class="hljs-number">2000</span>);<br>            &#125; <span class="hljs-keyword">catch</span> (InterruptedException e) &#123;<br>                e.printStackTrace();<br>            &#125;<br>            System.out.println(<span class="hljs-string">&quot;任务结束---&quot;</span> + LocalDateTime.now());<br>        &#125;, <span class="hljs-number">2000</span>, <span class="hljs-number">4000</span>, TimeUnit.MILLISECONDS);<br>    &#125;<br></code></pre></td></tr></table></figure>

<h4 id="DelayQueue-延迟任务"><a href="#DelayQueue-延迟任务" class="headerlink" title="DelayQueue 延迟任务"></a>DelayQueue 延迟任务</h4><ul>
<li><h5 id="DelayQueue是JDK提供的api，是一个延迟队列"><a href="#DelayQueue是JDK提供的api，是一个延迟队列" class="headerlink" title="DelayQueue是JDK提供的api，是一个延迟队列"></a>DelayQueue是JDK提供的api，是一个延迟队列</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Slf4j</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">DelayQueueDemo</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        DelayQueue&lt;SanYouTask&gt; sanYouTaskDelayQueue = <span class="hljs-keyword">new</span> <span class="hljs-title class_">DelayQueue</span>&lt;&gt;();<br><br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Thread</span>(() -&gt; &#123;<br>            <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    <span class="hljs-type">SanYouTask</span> <span class="hljs-variable">sanYouTask</span> <span class="hljs-operator">=</span> sanYouTaskDelayQueue.take();<br>                    log.info(<span class="hljs-string">&quot;获取到延迟任务:&#123;&#125;&quot;</span>, sanYouTask.getTaskContent());<br>                &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>                &#125;<br>            &#125;<br>        &#125;).start();<br><br>        log.info(<span class="hljs-string">&quot;提交延迟任务&quot;</span>);<br>        sanYouTaskDelayQueue.offer(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SanYouTask</span>(<span class="hljs-string">&quot;三友的java日记5s&quot;</span>, <span class="hljs-number">5L</span>));<br>        sanYouTaskDelayQueue.offer(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SanYouTask</span>(<span class="hljs-string">&quot;三友的java日记3s&quot;</span>, <span class="hljs-number">3L</span>));<br>        sanYouTaskDelayQueue.offer(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SanYouTask</span>(<span class="hljs-string">&quot;三友的java日记8s&quot;</span>, <span class="hljs-number">8L</span>));<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">SanYouTask</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Delayed</span> &#123;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String taskContent;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> Long triggerTime;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">SanYouTask</span><span class="hljs-params">(String taskContent, Long delayTime)</span> &#123;<br>        <span class="hljs-built_in">this</span>.taskContent = taskContent;<br>        <span class="hljs-built_in">this</span>.triggerTime = System.currentTimeMillis() + delayTime * <span class="hljs-number">1000</span>;<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">long</span> <span class="hljs-title function_">getDelay</span><span class="hljs-params">(TimeUnit unit)</span> &#123;<br>        <span class="hljs-keyword">return</span> unit.convert(triggerTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">compareTo</span><span class="hljs-params">(Delayed o)</span> &#123;<br>            <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.triggerTime.compareTo(((SanYouTask) o).triggerTime);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><code>getDelay</code>方法返回<strong>这个任务还剩多久时间可以执行</strong>，小于0的时候说明可以这个延迟任务到了执行的时间了。</li>
<li><code>compareTo</code>这个是<strong>对任务排序</strong>的，保证最先到延迟时间的任务排到队列的头。<ul>
<li><strong>taskContent</strong>：延迟任务的具体的内容</li>
<li><strong>delayTime</strong>：延迟时间，秒为单位</li>
</ul>
</li>
</ul>
<h5 id="实现原理"><a href="#实现原理" class="headerlink" title="实现原理"></a>实现原理</h5><blockquote>
<p>🍻 <code>offer</code>方法在提交任务的时候，会通过根据<code>compareTo</code>的实现对任务进行排序，将最先需要被执行的任务放到队列头。</p>
<p>🍛<code>take</code>方法获取任务的时候，会拿到队列头部的元素，也就是队列中最早需要被执行的任务，通过getDelay返回值判断任务是否需要被立刻执行，如果需要的话，就返回任务，如果不需要就会等待这个任务到延迟时间的剩余时间，当时间到了就会将任务返回。</p>
</blockquote>
<ul>
<li>效果如下：</li>
</ul>
<h4 id="Spring提供定时任务"><a href="#Spring提供定时任务" class="headerlink" title="Spring提供定时任务"></a>Spring提供定时任务</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@author</span> 邓哈哈</span><br><span class="hljs-comment"> * 2023/8/29 11:50</span><br><span class="hljs-comment"> * Function:</span><br><span class="hljs-comment"> * Version 1.0</span><br><span class="hljs-comment"> */</span><br> <br><span class="hljs-meta">@EnableScheduling</span><br><span class="hljs-meta">@Component</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Timer</span> &#123;<br>    <span class="hljs-meta">@Scheduled(cron = &quot;*/2 * * * * *&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">timer</span><span class="hljs-params">()</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;哈哈哈哈&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="如果有多个定时任务类，可以考虑把-EnableScheduling注解添加在启动类上"><a href="#如果有多个定时任务类，可以考虑把-EnableScheduling注解添加在启动类上" class="headerlink" title="如果有多个定时任务类，可以考虑把@EnableScheduling注解添加在启动类上"></a>如果有多个定时任务类，可以考虑把@EnableScheduling注解添加在启动类上</h5></li>
</ul>
<h4 id="Cron表达式"><a href="#Cron表达式" class="headerlink" title="Cron表达式"></a>Cron表达式</h4><ul>
<li><h5 id="在线生成工具：在线Cron表达式生成器-qqe2-com"><a href="#在线生成工具：在线Cron表达式生成器-qqe2-com" class="headerlink" title="在线生成工具：在线Cron表达式生成器 (qqe2.com)"></a>在线生成工具：<a target="_blank" rel="noopener" href="https://cron.qqe2.com/">在线Cron表达式生成器 (qqe2.com)</a></h5></li>
<li><h5 id="简单地介绍下如何使用吧：（2023-08-25早）"><a href="#简单地介绍下如何使用吧：（2023-08-25早）" class="headerlink" title="简单地介绍下如何使用吧：（2023/08/25早）"></a>简单地介绍下如何使用吧：（2023/08/25早）</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230829122937976.png" alt="image-20230829122937976"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230829123041111.png" alt="image-20230829123041111"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230829123201856.png" alt="image-20230829123201856"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231022143837175.png" alt="image-20231022143837175"></p>
<h3 id="项目目录显示问题"><a href="#项目目录显示问题" class="headerlink" title="项目目录显示问题"></a>项目目录显示问题</h3><p>昨天重构项目之后，项目目录变成了这样，待解决：<strong>（2024/01/19午）</strong></p>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20240119141255836.png" alt="image-20240119141255836"></p>
<p>解决了，取消这个显示就行了：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240119141720399.png" alt="image-20240119141720399"></p>
<h2 id="设置技巧"><a href="#设置技巧" class="headerlink" title="设置技巧"></a>设置技巧</h2><h3 id="注释对齐"><a href="#注释对齐" class="headerlink" title="注释对齐"></a>注释对齐</h3><ul>
<li><h5 id="按如下步骤进行设置："><a href="#按如下步骤进行设置：" class="headerlink" title="按如下步骤进行设置："></a>按如下步骤进行设置：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231008090705284.png" alt="image-20231008090705284"></p>
<ul>
<li>当我们在这里打上注释：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231008090833683.png" alt="image-20231008090833683"></p>
<ul>
<li>按 <strong>Ctrl + / 快捷键</strong>，就是这样的效果：<strong>（2023/10/08早）</strong></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20231008090915001.png" alt="image-20231008090915001"></p>
<h2 id="Java基础"><a href="#Java基础" class="headerlink" title="Java基础"></a>Java基础</h2><ul>
<li><h5 id="本人太菜，不定时巩固Java基础，今天巩固如下操作：（2023-08-14早）"><a href="#本人太菜，不定时巩固Java基础，今天巩固如下操作：（2023-08-14早）" class="headerlink" title="本人太菜，不定时巩固Java基础，今天巩固如下操作：（2023/08/14早）"></a>本人太菜，不定时巩固Java基础，今天巩固如下操作：（2023/08/14早）</h5><ul>
<li><p>Radom 随机数</p>
</li>
<li><p>Collections 排序</p>
</li>
<li><p>Stream 流遍历</p>
</li>
<li><p>System.currentTimeMillis() 计时</p>
</li>
</ul>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// Radom 随机数</span><br><span class="hljs-type">Random</span> <span class="hljs-variable">random</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Random</span>();<br>     ArrayList&lt;Double&gt; arrayList = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>     <span class="hljs-type">long</span> <span class="hljs-variable">startTime</span> <span class="hljs-operator">=</span> System.currentTimeMillis();<br>     <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">100000</span>; i++) &#123;<br>         arrayList.add(random.nextDouble());<br>     &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// Collections 排序</span><br><span class="hljs-comment">// 第一种方法</span><br>      Collections.sort(arrayList, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Comparator</span>&lt;Double&gt;() &#123;<br>          <span class="hljs-meta">@Override</span><br>          <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">compare</span><span class="hljs-params">(Double o1, Double o2)</span> &#123;<br>              <span class="hljs-keyword">return</span> o1.compareTo(o2);<br>          &#125;<br>      &#125;);<br>      <span class="hljs-comment">// 第二种方法</span><br>      Collections.sort(arrayList, (o1, o2) -&gt; &#123;<br>          <span class="hljs-keyword">return</span> o1.compareTo(o2);<br>      &#125;);<br>      <span class="hljs-comment">// 第三种方法</span><br>      Collections.sort(arrayList, (o1, o2) -&gt; o1.compareTo(o2));<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// Stream 流便利      </span><br>       <span class="hljs-comment">// 第一种方法</span><br>        arrayList.forEach(item -&gt; &#123;<br>            System.out.println(item);<br>        &#125;);<br><br>        <span class="hljs-comment">// 第二种方法</span><br>        arrayList.stream().forEach(item -&gt; System.out.println(item));<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java">List&lt;Integer&gt; userList = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br><br>       <span class="hljs-type">Random</span> <span class="hljs-variable">rand</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Random</span>();<br>       <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10000</span>; i++) &#123;<br>           userList.add(rand.nextInt(<span class="hljs-number">1000</span>));<br>       &#125;<br><br>       List&lt;Integer&gt; userList2 = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>       userList2.addAll(userList);<br><br>       <span class="hljs-type">Long</span> <span class="hljs-variable">startTime1</span> <span class="hljs-operator">=</span> System.currentTimeMillis();<br>       userList2.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());<br>       System.out.println(<span class="hljs-string">&quot;stream.sort耗时：&quot;</span> + (System.currentTimeMillis() - startTime1) + <span class="hljs-string">&quot;ms&quot;</span>);<br><br>       <span class="hljs-type">Long</span> <span class="hljs-variable">startTime</span> <span class="hljs-operator">=</span> System.currentTimeMillis();<br>       userList.sort(Comparator.comparing(Integer::intValue));<br>       System.out.println(<span class="hljs-string">&quot;List.sort()耗时：&quot;</span> + (System.currentTimeMillis() - startTime) + <span class="hljs-string">&quot;ms&quot;</span>);<br></code></pre></td></tr></table></figure>

<ul>
<li>有时间总结下 SpringBoot 中的定时任务：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7158851405531316254">我终于会写 Java 的定时任务了！ - 掘金 (juejin.cn)</a></li>
</ul>
<h3 id="Date-Time-API"><a href="#Date-Time-API" class="headerlink" title="Date/Time API"></a>Date/Time API</h3><ul>
<li><h5 id="学习以下内容可以参考这篇博客：8个你必须知道的Java8新特性，让你的代码变得优雅！-掘金-juejin-cn"><a href="#学习以下内容可以参考这篇博客：8个你必须知道的Java8新特性，让你的代码变得优雅！-掘金-juejin-cn" class="headerlink" title="学习以下内容可以参考这篇博客：8个你必须知道的Java8新特性，让你的代码变得优雅！ - 掘金 (juejin.cn)"></a>学习以下内容可以参考这篇博客：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7240697872160833596">8个你必须知道的Java8新特性，让你的代码变得优雅！ - 掘金 (juejin.cn)</a></h5></li>
<li><p>在 Java 8 中引入了全新的日期时间处理类库，使得处理日期时间变得更加方便和易于理解</p>
</li>
<li><h5 id="以下是-java-time-包中最重要的一些类：（2023-08-18午）"><a href="#以下是-java-time-包中最重要的一些类：（2023-08-18午）" class="headerlink" title="以下是 java.time 包中最重要的一些类：（2023/08/18午）"></a>以下是 <code>java.time</code> 包中最重要的一些类：（2023/08/18午）</h5><ul>
<li>LocalDate：表示日期，如 2022 年 5 月 15 日。</li>
<li><code>LocalTime</code>：表示时间，如 13:45:30。</li>
<li><code>LocalDateTime</code>：代表日期和时间，比如 2022 年 5 月 15 日 13:45:30。</li>
<li><code>ZonedDateTime</code>：代表带有时区的日期时间，在上述所有日期时间类型的基础上，还提供了时区信息。</li>
<li><code>Duration</code>：在两个时间点之间表示时间量。</li>
<li><code>Period</code>：在两个日期之间表示天、周、月或年的数量。</li>
<li><code>DateTimeFormatter</code>：可以将日期时间对象按照指定的格式进行格式化或者解析。</li>
</ul>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">()</span> &#123;<br>    <span class="hljs-comment">// 获取日期</span><br>    <span class="hljs-type">LocalDateTime</span> <span class="hljs-variable">dateTime</span> <span class="hljs-operator">=</span> LocalDateTime.now();<br>    System.out.println(dateTime);<br>    <span class="hljs-comment">// 日期格式</span><br>    <span class="hljs-type">DateTimeFormatter</span> <span class="hljs-variable">pattern</span> <span class="hljs-operator">=</span> DateTimeFormatter.ofPattern(<span class="hljs-string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);<br>    <span class="hljs-type">String</span> <span class="hljs-variable">format</span> <span class="hljs-operator">=</span> dateTime.format(pattern);<br>    System.out.println(format);<br><br>    <span class="hljs-type">String</span> <span class="hljs-variable">now</span> <span class="hljs-operator">=</span> LocalDateTime.now().format(DateTimeFormatter.ofPattern(<span class="hljs-string">&quot;yyyy年MM月dd日 HH时mm分ss秒&quot;</span>));<br>    System.out.println(now);<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test2</span><span class="hljs-params">()</span> &#123;<br>     <span class="hljs-comment">// 获取日期</span><br>     <span class="hljs-type">Duration</span> <span class="hljs-variable">between</span> <span class="hljs-operator">=</span> Duration.between(LocalDate.of(<span class="hljs-number">2022</span>, Month.JULY, <span class="hljs-number">10</span>), LocalDate.now());<br>     System.out.println(between);<br>     <span class="hljs-type">Duration</span> <span class="hljs-variable">between1</span> <span class="hljs-operator">=</span> Duration.between(LocalTime.of(<span class="hljs-number">12</span>, <span class="hljs-number">29</span>, <span class="hljs-number">10</span>), LocalDate.now());<br>     System.out.println(between1);<br> &#125;<br></code></pre></td></tr></table></figure>

<h3 id="Optional-容器类型"><a href="#Optional-容器类型" class="headerlink" title="Optional 容器类型"></a>Optional 容器类型</h3><ul>
<li><h5 id="ofNullable-方法：创建一个可能包含-null-值的-Optional-对象（2023-08-18午）"><a href="#ofNullable-方法：创建一个可能包含-null-值的-Optional-对象（2023-08-18午）" class="headerlink" title="ofNullable() 方法：创建一个可能包含 null 值的 Optional 对象（2023/08/18午）"></a>ofNullable() 方法：创建一个可能包含 null 值的 Optional 对象（2023/08/18午）</h5></li>
<li><h5 id="isPresent-方法：判断-Optional-中是否存在值。返回ture表示存在值-返回false表示为null"><a href="#isPresent-方法：判断-Optional-中是否存在值。返回ture表示存在值-返回false表示为null" class="headerlink" title="isPresent() 方法：判断 Optional 中是否存在值。返回ture表示存在值 返回false表示为null"></a>isPresent() 方法：判断 Optional 中是否存在值。返回ture表示存在值 返回false表示为null</h5></li>
<li><h5 id="get-方法：如果-Optional-的值存在则返回该值，否则抛出-NoSuchElementException-异常。"><a href="#get-方法：如果-Optional-的值存在则返回该值，否则抛出-NoSuchElementException-异常。" class="headerlink" title="get() 方法：如果 Optional 的值存在则返回该值，否则抛出 NoSuchElementException 异常。"></a>get() 方法：如果 Optional 的值存在则返回该值，否则抛出 NoSuchElementException 异常。</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test3</span><span class="hljs-params">()</span> &#123;<br>    <span class="hljs-comment">// 判断值是否为空</span><br>    Optional&lt;String&gt; optional = Optional.of(<span class="hljs-string">&quot;hhh&quot;</span>);<br>    <span class="hljs-keyword">if</span> (optional.isPresent()) &#123;<br>        System.out.println(optional.get());<br>    &#125;<br><br>    Optional.of(<span class="hljs-string">&quot;hhh&quot;</span>).ifPresent(System.out::println);<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test4</span><span class="hljs-params">(User user)</span> &#123;<br>    Optional.ofNullable(user).map(User::getName).ifPresentOrElse(out::println, user != <span class="hljs-literal">null</span> ?      user.setName(<span class="hljs-string">&quot;ccc&quot;</span>) : <span class="hljs-literal">null</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="BigDecimal"><a href="#BigDecimal" class="headerlink" title="BigDecimal"></a>BigDecimal</h3><ul>
<li><h5 id="使用BigDecimal需要注意的6点：（2023-08-19早）"><a href="#使用BigDecimal需要注意的6点：（2023-08-19早）" class="headerlink" title="使用BigDecimal需要注意的6点：（2023/08/19早）"></a>使用BigDecimal需要注意的6点：（2023/08/19早）</h5><ul>
<li>构造初始化</li>
<li>加减乘除</li>
<li>设置精度</li>
<li>去掉末尾的0</li>
<li>转换为Double</li>
<li>比较大小</li>
</ul>
</li>
<li><p><a target="_blank" rel="noopener" href="https://juejin.cn/post/7207617774633320504#comment">BigDecimal不可触碰的6个坑 - 掘金 (juejin.cn)</a></p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test5</span><span class="hljs-params">()</span> &#123;<br>      <span class="hljs-comment">// 1.两个BigDecimal对象</span><br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">dec1</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-string">&quot;1.3&quot;</span>);<br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">dec2</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-string">&quot;1.3&quot;</span>);<br>      <br>      <span class="hljs-comment">// 2.加减乘除</span><br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">add</span> <span class="hljs-operator">=</span> dec1.add(dec2);<br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">subtract</span> <span class="hljs-operator">=</span> dec1.subtract(dec2);<br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">multiply</span> <span class="hljs-operator">=</span> dec1.multiply(dec2);<br>      <br>      <span class="hljs-comment">// 3.设置精度</span><br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">divide</span> <span class="hljs-operator">=</span> dec1.divide(dec2).setScale(<span class="hljs-number">3</span>, RoundingMode.HALF_DOWN);<br>      <br>      out.println(add);<br>      out.println(subtract);<br>      out.println(multiply);<br>      System.out.println(divide);<br>      <br>      <span class="hljs-comment">// 4.去掉末尾的0</span><br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">bigDecimal</span> <span class="hljs-operator">=</span> divide.stripTrailingZeros();<br>      out.println(bigDecimal);<br>      <br>      <span class="hljs-comment">// 5.转换为Double</span><br>      <span class="hljs-type">BigDecimal</span> <span class="hljs-variable">value</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-string">&quot;1888977466432.1241341341413414&quot;</span>);<br>      <span class="hljs-type">double</span> <span class="hljs-variable">doubleValue</span> <span class="hljs-operator">=</span> value.doubleValue();<br>      out.println(doubleValue);<br>      <span class="hljs-type">double</span> <span class="hljs-variable">doubleValue1</span> <span class="hljs-operator">=</span> value.toBigInteger().doubleValue();<br>      out.println(doubleValue1);<br>      <br>      <span class="hljs-comment">// 6.比较大小</span><br>      out.println(add.compareTo(subtract) &gt; <span class="hljs-number">0</span> ? <span class="hljs-string">&quot;add大于sub&quot;</span> : <span class="hljs-string">&quot;add小于sub&quot;</span>);<br>  &#125;<br></code></pre></td></tr></table></figure>

<h3 id="数组转字符串"><a href="#数组转字符串" class="headerlink" title="数组转字符串"></a>数组转字符串</h3><ul>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/haohaiyou/p/16806399.html">JAVA 数组转字符串 - 一只忙碌的蜗牛 - 博客园 (cnblogs.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_35939148/article/details/131495097">Java中数组转字符串的五种方式效率比较_java数组转字符串_likaistart的博客-CSDN博客</a></li>
<li><h5 id="数组如何转字符串？我们有好多种方案"><a href="#数组如何转字符串？我们有好多种方案" class="headerlink" title="数组如何转字符串？我们有好多种方案"></a>数组如何转字符串？我们有好多种方案</h5></li>
<li><h5 id="我们经常能遇到这样的情景："><a href="#我们经常能遇到这样的情景：" class="headerlink" title="我们经常能遇到这样的情景："></a>我们经常能遇到这样的情景：</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 创建一个List</span><br>List&lt;String&gt; list = Arrays.asList(<span class="hljs-string">&quot;Apple&quot;</span>, <span class="hljs-string">&quot;Banana&quot;</span>, <span class="hljs-string">&quot;Cherry&quot;</span>, <span class="hljs-string">&quot;Date&quot;</span>, <span class="hljs-string">&quot;Elderberry&quot;</span>);<br><span class="hljs-comment">// 创建一个String数组</span><br>String[] arr = &#123;<span class="hljs-string">&quot;0&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>, <span class="hljs-string">&quot;2&quot;</span>, <span class="hljs-string">&quot;3&quot;</span>, <span class="hljs-string">&quot;4&quot;</span>, <span class="hljs-string">&quot;5&quot;</span>&#125;;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="如果是List，则有如下转字符串的方法：（2023-09-20晚）"><a href="#如果是List，则有如下转字符串的方法：（2023-09-20晚）" class="headerlink" title="如果是List，则有如下转字符串的方法：（2023/09/20晚）"></a>如果是List，则有如下转字符串的方法：（2023/09/20晚）</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// stream流</span><br><span class="hljs-type">String</span> <span class="hljs-variable">collect</span> <span class="hljs-operator">=</span> list.stream().collect(Collectors.joining(<span class="hljs-string">&quot;,&quot;</span>));<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//org.apache.commons.lang3包</span><br><span class="hljs-type">String</span> <span class="hljs-variable">join</span> <span class="hljs-operator">=</span>  StringUtils.join(longList, <span class="hljs-string">&quot;,&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// StringBuilder</span><br><span class="hljs-type">StringBuilder</span> <span class="hljs-variable">sb</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">StringBuilder</span>();<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; list.size(); i++) &#123;<br>            sb.append(i);<br>            <span class="hljs-keyword">if</span> (i &lt; list.size() - <span class="hljs-number">1</span>) &#123;<br>                sb.append(<span class="hljs-string">&quot;,&quot;</span>);<br>         &#125;<br>   &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// String.join</span><br><span class="hljs-type">String</span> <span class="hljs-variable">join</span> <span class="hljs-operator">=</span> String.join(<span class="hljs-string">&quot;,&quot;</span>, list);<br></code></pre></td></tr></table></figure>

<ul>
<li><p>以上方法，转换所消耗的<strong>时间越来越少</strong>，<strong>效率越来越高</strong></p>
</li>
<li><h5 id="如果是String-，则有如下转字符串的方法：（2023-09-20晚）"><a href="#如果是String-，则有如下转字符串的方法：（2023-09-20晚）" class="headerlink" title="如果是String[]，则有如下转字符串的方法：（2023/09/20晚）"></a>如果是String[]，则有如下转字符串的方法：（2023/09/20晚）</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//org.apache.commons.lang3包</span><br><span class="hljs-type">String</span> <span class="hljs-variable">join</span> <span class="hljs-operator">=</span>  StringUtils.join(longList, <span class="hljs-string">&quot;,&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// String.join</span><br><span class="hljs-type">String</span> <span class="hljs-variable">join</span> <span class="hljs-operator">=</span> String.join(<span class="hljs-string">&quot;,&quot;</span>, list);<br></code></pre></td></tr></table></figure>

<h3 id="Java8中的Map函数"><a href="#Java8中的Map函数" class="headerlink" title="Java8中的Map函数"></a>Java8中的Map函数</h3><h4 id="computeIfAbsent"><a href="#computeIfAbsent" class="headerlink" title="computeIfAbsent"></a>computeIfAbsent</h4><ul>
<li>如果指定的key不存在于Map中，那么会执行指定的函数来计算并将结果作为value放入到Map中。</li>
<li>如果指定的key已经存在于Map中，则不会执行计算函数，而是直接返回已存在的value。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">ComputeIfAbsentExample</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        Map&lt;String, Integer&gt; map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;&gt;();<br>        map.put(<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-number">1</span>);<br>        map.put(<span class="hljs-string">&quot;banana&quot;</span>, <span class="hljs-number">2</span>);<br>        <br>        <span class="hljs-comment">// 当key不存在时，执行计算函数并将结果放入Map</span><br>        map.computeIfAbsent(<span class="hljs-string">&quot;orange&quot;</span>, key -&gt; &#123;<br>            System.out.println(<span class="hljs-string">&quot;Performing computation for orange&quot;</span>);<br>            <span class="hljs-keyword">return</span> key.length();<br>        &#125;);<br>        <br>        <span class="hljs-comment">// 当key已存在时，不执行计算函数，直接返回已存在的value</span><br>        map.computeIfAbsent(<span class="hljs-string">&quot;apple&quot;</span>, key -&gt; &#123;<br>            System.out.println(<span class="hljs-string">&quot;Performing computation for apple&quot;</span>);<br>            <span class="hljs-keyword">return</span> key.length();<br>        &#125;);<br>        <br>        System.out.println(map);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="computeIfPresent"><a href="#computeIfPresent" class="headerlink" title="computeIfPresent"></a>computeIfPresent</h4><ul>
<li>如果指定的key存在于Map中，那么会执行指定的函数来计算并将结果作为新的value放入到Map中。</li>
<li>如果指定的key不存在于Map中，则不会执行计算函数，什么也不做</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">ComputeIfPresentExample</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        Map&lt;String, Integer&gt; map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;&gt;();<br>        map.put(<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-number">1</span>);<br>        map.put(<span class="hljs-string">&quot;banana&quot;</span>, <span class="hljs-number">2</span>);<br>        <br>        map.computeIfPresent(<span class="hljs-string">&quot;apple&quot;</span>, (key, value) -&gt; value * <span class="hljs-number">2</span>);<br>        map.computeIfPresent(<span class="hljs-string">&quot;orange&quot;</span>, (key, value) -&gt; value * <span class="hljs-number">2</span>);<br>        <br>        System.out.println(map);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="compute"><a href="#compute" class="headerlink" title="compute"></a>compute</h4><ul>
<li>而<code>compute()</code>函数无论旧的value是否为<code>null</code>，都会调用计算函数来计算新的value，并将计算结果更新到Map中。</li>
<li>如果计算结果为<code>null</code>，则会将对应的key从Map中移除。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">ComputeExample</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        Map&lt;String, Integer&gt; map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;&gt;();<br>        map.put(<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-number">1</span>);<br>        map.put(<span class="hljs-string">&quot;banana&quot;</span>, <span class="hljs-literal">null</span>);<br><br>        <span class="hljs-comment">// 使用computeIfPresent()</span><br>        map.computeIfPresent(<span class="hljs-string">&quot;apple&quot;</span>, (key, value) -&gt; value * <span class="hljs-number">2</span>);<br>        map.computeIfPresent(<span class="hljs-string">&quot;banana&quot;</span>, (key, value) -&gt; value * <span class="hljs-number">2</span>);<br>        System.out.println(map); <span class="hljs-comment">// 输出: &#123;apple=2&#125;</span><br><br>        <span class="hljs-comment">// 使用compute()</span><br>        map.compute(<span class="hljs-string">&quot;apple&quot;</span>, (key, value) -&gt; value + <span class="hljs-number">3</span>);<br>        map.compute(<span class="hljs-string">&quot;banana&quot;</span>, (key, value) -&gt; value + <span class="hljs-number">3</span>);<br>        System.out.println(map); <span class="hljs-comment">// 输出: &#123;apple=5, banana=null&#125;</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="merge"><a href="#merge" class="headerlink" title="merge"></a>merge</h4><ul>
<li>这个目前还不太明白，按下不表：</li>
</ul>
<figure class="highlight livescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs livescript"><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.<span class="hljs-built_in">Map</span>;<br><br>public <span class="hljs-keyword">class</span> <span class="hljs-title class_">MergeExample</span> &#123;<br>    public <span class="hljs-keyword">static</span> <span class="hljs-literal">void</span> main(<span class="hljs-built_in">String</span>[] args) &#123;<br>        <span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, Integer&gt; map1 = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();<br>        map1.put(<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-number">1</span>);<br>        map1.put(<span class="hljs-string">&quot;banana&quot;</span>, <span class="hljs-number">2</span>);<br><br>        <span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, Integer&gt; map2 = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();<br>        map2.put(<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-number">5</span>);<br>        map2.put(<span class="hljs-string">&quot;orange&quot;</span>, <span class="hljs-number">3</span>);<br><br>        map2.forEach<span class="hljs-function"><span class="hljs-params">((key, value) -&gt; &#123;</span></span><br><span class="hljs-params"><span class="hljs-function">            map1.merge(key, value, (oldValue, newValue) -&gt; oldValue + newValue);</span></span><br><span class="hljs-params"><span class="hljs-function">        &#125;)</span>;</span><br><span class="hljs-function"></span><br><span class="hljs-function">        <span class="hljs-title">System</span>.<span class="hljs-title">out</span>.<span class="hljs-title">println</span><span class="hljs-params">(map1)</span>; // 输出: &#123;<span class="hljs-title">orange</span>=3, <span class="hljs-title">apple</span>=6, <span class="hljs-title">banana</span>=2&#125;</span><br><span class="hljs-function">    &#125;</span><br><span class="hljs-function">&#125;</span><br></code></pre></td></tr></table></figure>

<h4 id="getOrDefalut"><a href="#getOrDefalut" class="headerlink" title="getOrDefalut"></a>getOrDefalut</h4><ul>
<li>当 key 存在时，取对应 value，否则取默认值</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-type">int</span> <span class="hljs-title function_">firstUniqChar</span><span class="hljs-params">(String s)</span> &#123;<br>       <span class="hljs-keyword">if</span> (s == <span class="hljs-literal">null</span> || s.length() == <span class="hljs-number">0</span>) &#123;<br>           <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>       &#125;<br>       Map&lt;Character, Integer&gt; frequency = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;Character, Integer&gt;();<br>       <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; s.length(); ++i) &#123;<br>           <span class="hljs-type">char</span> <span class="hljs-variable">ch</span> <span class="hljs-operator">=</span> s.charAt(i);<br>           frequency.put(ch, frequency.getOrDefault(ch, <span class="hljs-number">0</span>) + <span class="hljs-number">1</span>);<br>       &#125;<br>       <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; s.length(); ++i) &#123;<br>           <span class="hljs-keyword">if</span> (frequency.get(s.charAt(i)) == <span class="hljs-number">1</span>) &#123;<br>               <span class="hljs-keyword">return</span> i;<br>           &#125;<br>       &#125;<br>       <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br>   &#125;<br></code></pre></td></tr></table></figure>

<h4 id="putIfAbsent"><a href="#putIfAbsent" class="headerlink" title="putIfAbsent"></a>putIfAbsent</h4><ul>
<li>与 put 的区别：如果有重复 key，保存的是<strong>最早存入的键值对</strong> <strong>（2023/10/08早）</strong></li>
</ul>
<h4 id="forEach"><a href="#forEach" class="headerlink" title="forEach"></a>forEach</h4><h3 id="Java8中的Stream流函数"><a href="#Java8中的Stream流函数" class="headerlink" title="Java8中的Stream流函数"></a>Java8中的Stream流函数</h3><h4 id="groupingBy"><a href="#groupingBy" class="headerlink" title="groupingBy"></a>groupingBy</h4><ul>
<li>将集合中的元素，<strong>按某个属性进行分组</strong>，<strong>返回的结果</strong>是一个 <strong>Map 集合</strong> <strong>（2023/10/08早）</strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Person</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> age;<br>    <span class="hljs-keyword">private</span> String name;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">Person</span><span class="hljs-params">(<span class="hljs-type">int</span> age, String name)</span> &#123;<br>        <span class="hljs-built_in">this</span>.age = age;<br>        <span class="hljs-built_in">this</span>.name = name;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">GroupingByExample</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        List&lt;Person&gt; people = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        people.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Person</span>(<span class="hljs-number">25</span>, <span class="hljs-string">&quot;Alice&quot;</span>));<br>        people.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Person</span>(<span class="hljs-number">30</span>, <span class="hljs-string">&quot;Bob&quot;</span>));<br>        people.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Person</span>(<span class="hljs-number">25</span>, <span class="hljs-string">&quot;Charlie&quot;</span>));<br>        people.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Person</span>(<span class="hljs-number">40</span>, <span class="hljs-string">&quot;David&quot;</span>));<br>        people.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Person</span>(<span class="hljs-number">30</span>, <span class="hljs-string">&quot;Emily&quot;</span>));<br><br>        Map&lt;Integer, List&lt;Person&gt;&gt; groups = people.stream()<br>                .collect(Collectors.groupingBy(Person::getAge));<br><br>        System.out.println(groups);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="泛型理解"><a href="#泛型理解" class="headerlink" title="泛型理解"></a>泛型理解</h3><ul>
<li><h5 id="推荐学习：我真的了解泛型吗？-掘金-juejin-cn"><a href="#推荐学习：我真的了解泛型吗？-掘金-juejin-cn" class="headerlink" title="推荐学习：我真的了解泛型吗？ - 掘金 (juejin.cn)"></a>推荐学习：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7263810695459504189#heading-8">我真的了解泛型吗？ - 掘金 (juejin.cn)</a></h5></li>
<li><h5 id="学习Java泛型：（2023-10-13晚）"><a href="#学习Java泛型：（2023-10-13晚）" class="headerlink" title="学习Java泛型：（2023/10/13晚）"></a>学习Java泛型：（2023/10/13晚）</h5><ul>
<li>泛型类</li>
<li>泛型接口</li>
<li>泛型方法：返回值、入参位置、方法体中</li>
<li>个人感受：泛型很好理解：我们经常讲到一个对象实例的就是以类作为模板创建的，那么也可以讲一个普通类可以以泛型类作为模板；那么泛型是用来干嘛的呢，我们为什么要使用泛型呢？其实，所有的泛型类在编译后生成的字节码与普通类无异，因为在编译前，所有泛型类型就被擦除了。所以我们可以把泛型看作一个语法糖，将类型转换的校验提前在编译时，减少类型转换错误的发生，使编写的程序更加具有健壮性。</li>
</ul>
</li>
<li><h5 id="我觉得以下这段总结更妙："><a href="#我觉得以下这段总结更妙：" class="headerlink" title="我觉得以下这段总结更妙："></a>我觉得以下这段总结更妙：</h5></li>
</ul>
<blockquote>
<p>泛型是Java语言中的一项强大的特性，它允许在编译时指定类、接口或方法的参数类型，从而在编译阶段就能够进行类型检查。这样可以减少类型转换的错误，并提高代码的安全性和可读性。</p>
<p>通过使用泛型，我们可以在编译时捕捉到一些类型错误，而不是在运行时才发现，这样可以避免一些潜在的bug。泛型还可以增加代码的可重用性和灵活性，因为泛型类、接口和方法可以用于多种不同的类型，而无需针对每一种类型单独编写或重复编写相似的代码。</p>
<p>总的来说，通过使用泛型，我们可以在编写Java代码时更好地约束和使用类型信息，减少类型错误，提高代码的可读性和健壮性。</p>
</blockquote>
<ul>
<li><h5 id="了解泛型的实现原理，理解泛型的使用方式，更加加深了我们对-Java-语言的理解"><a href="#了解泛型的实现原理，理解泛型的使用方式，更加加深了我们对-Java-语言的理解" class="headerlink" title="了解泛型的实现原理，理解泛型的使用方式，更加加深了我们对 Java 语言的理解"></a>了解泛型的实现原理，理解泛型的使用方式，更加加深了我们对 Java 语言的理解</h5></li>
</ul>
<h2 id="良心插件"><a href="#良心插件" class="headerlink" title="良心插件"></a>良心插件</h2><h3 id="carbon-now-sh"><a href="#carbon-now-sh" class="headerlink" title="carbon-now-sh"></a>carbon-now-sh</h3><ul>
<li><h5 id="carbon-now-sh：代码贴图工具（2023-08-20晚）"><a href="#carbon-now-sh：代码贴图工具（2023-08-20晚）" class="headerlink" title="carbon-now-sh：代码贴图工具（2023/08/20晚）"></a>carbon-now-sh：代码贴图工具（2023/08/20晚）</h5></li>
<li><p>选择一段代码，右键菜单点击 Open in carbon.now.sh：</p>
</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820220508484.png" alt="image-20230820220508484"></p>
<ul>
<li><h5 id="在弹出的网页页面中，可以调整代码风格，点击导出就下载成功了"><a href="#在弹出的网页页面中，可以调整代码风格，点击导出就下载成功了" class="headerlink" title="在弹出的网页页面中，可以调整代码风格，点击导出就下载成功了~"></a>在弹出的网页页面中，可以调整代码风格，点击导出就下载成功了~</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820220640005.png" alt="image-20230820220640005"></p>
<h3 id="MybatisX-Genetator"><a href="#MybatisX-Genetator" class="headerlink" title="MybatisX-Genetator"></a>MybatisX-Genetator</h3><ul>
<li><h5 id="MybatisX-Genetator：代码自动生成器"><a href="#MybatisX-Genetator：代码自动生成器" class="headerlink" title="MybatisX-Genetator：代码自动生成器"></a>MybatisX-Genetator：代码自动生成器</h5></li>
<li><h5 id="连接到数据库后，在一个表右键菜单点击-MybatisX-Genetator：（2023-08-20晚）"><a href="#连接到数据库后，在一个表右键菜单点击-MybatisX-Genetator：（2023-08-20晚）" class="headerlink" title="连接到数据库后，在一个表右键菜单点击 MybatisX-Genetator：（2023/08/20晚）"></a>连接到数据库后，在一个表右键菜单点击 MybatisX-Genetator：（2023/08/20晚）</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820220815784.png" alt="image-20230820220815784"></p>
<ul>
<li>选择代码生成位置、编码格式、包名等信息：</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820221142630.png" alt="image-20230820221142630"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820221240754.png" alt="image-20230820221240754"></p>
<ul>
<li><h5 id="点击Finish，直接生成domain、service、serviceImpl、mapper、mapperXml："><a href="#点击Finish，直接生成domain、service、serviceImpl、mapper、mapperXml：" class="headerlink" title="点击Finish，直接生成domain、service、serviceImpl、mapper、mapperXml："></a>点击Finish，直接生成domain、service、serviceImpl、mapper、mapperXml：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230820221655077.png" alt="image-20230820221655077"></p>
<h3 id="GenerateAllSetter"><a href="#GenerateAllSetter" class="headerlink" title="GenerateAllSetter"></a>GenerateAllSetter</h3><ul>
<li>这是一款<strong>快速生成对象的 getter、setter方法</strong>的插件，对日常的代码开发很有帮助    <strong>（2023/10/05晚）</strong></li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20231005195426227.png" alt="image-20231005195426227"></p>
<ul>
<li>我们定义一个 <strong>User 对象</strong>，右键，即可<strong>快速生成该对象的 geeter、setter 方法</strong>：</li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20231005195434856.png" alt="image-20231005195434856"></p>
<ul>
<li>我在开发项目的过程中，<strong>转换 entity 为 对应 VO 对象</strong>时，使用该插件居多：<strong>（2023/10/05晚）</strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 转换 teamList为 teamVOList</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@param</span> teamList teamList</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@return</span> teamVOList</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> List&lt;TeamVO&gt; <span class="hljs-title function_">getTeamVOByTeam</span><span class="hljs-params">(List&lt;Team&gt; teamList)</span> &#123;<br>    <span class="hljs-keyword">return</span> teamList.stream().map(team -&gt; &#123;<br>        <span class="hljs-type">Long</span> <span class="hljs-variable">userId</span> <span class="hljs-operator">=</span> team.getUserId();<br>        <span class="hljs-type">String</span> <span class="hljs-variable">userName</span> <span class="hljs-operator">=</span> userService.getById(userId).getUsername();<br>        <span class="hljs-type">TeamVO</span> <span class="hljs-variable">teamVO</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">TeamVO</span>();<br><br>        teamVO.setId(team.getId());<br>        teamVO.setName(team.getName());<br>        teamVO.setDescription(team.getDescription());<br>        teamVO.setMaxNum(team.getMaxNum());<br>        teamVO.setUserName(userName);<br>        teamVO.setImgUrl(team.getImgUrl());<br>        teamVO.setJoinNum(team.getJoinNum());<br>        teamVO.setStatus(team.getStatus());<br>        teamVO.setExpireTime(team.getExpireTime());<br>        teamVO.setCreateTime(team.getCreateTime());<br>        teamVO.setUpdateTime(team.getUpdateTime());<br>        teamVO.setIsDelete(team.getIsDelete());<br>        teamVO.setAnnouncement(team.getAnnouncement());<br><br>        <span class="hljs-keyword">return</span> teamVO;<br>    &#125;).collect(Collectors.toList());<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="String-Manipulation"><a href="#String-Manipulation" class="headerlink" title="String Manipulation"></a>String Manipulation</h3><p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240128171150346.png" alt="image-20240128171150346"></p>
<p>可以实现快速将选定字符串转换为大写：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240128171314634.png" alt="image-20240128171314634"></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/deng-2022/blog_2/categories/IDEA/" class="category-chain-item">IDEA</a>
  
  
    <span>></span>
    
  <a href="/deng-2022/blog_2/categories/IDEA/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/deng-2022/blog_2/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/deng-2022/blog_2/tags/IDEA/">#IDEA</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化</div>
      <div>https://atomgit.com/deng-2022/blog_2/2023/07/06/打造流畅编码之旅：IntelliJ IDEA 的高效使用技巧与工作流程优化/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年7月6日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年5月13日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/deng-2022/blog_2/2023/07/06/%E5%87%A4%E5%87%B0%E6%B6%85%E6%A7%83%EF%BC%9ASpring%20Boot%20%E5%BC%80%E5%8F%91%E4%B9%8B%E8%B7%AF%E4%B8%8A%E7%9A%84%E5%9D%8E%E5%9D%B7%E4%B8%8E%E6%88%90%E9%95%BF/" title="凤凰涅槃：Spring Boot 开发之路上的坎坷与成长">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">凤凰涅槃：Spring Boot 开发之路上的坎坷与成长</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/deng-2022/blog_2/2023/07/02/%E7%90%86%E8%A7%A3npm%E3%80%81pnpm%E5%92%8Cyarn%EF%BC%9A%E9%80%89%E5%87%BA%E6%9C%80%E9%80%82%E5%90%88%E4%BD%A0%E7%9A%84%E5%8C%85%E7%AE%A1%E7%90%86%E5%99%A8/" title="理解npm、pnpm和yarn：选出最适合你的包管理器">
                        <span class="hidden-mobile">理解npm、pnpm和yarn：选出最适合你的包管理器</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/deng-2022/blog_2/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/deng-2022/blog_2/js/events.js" ></script>
<script  src="/deng-2022/blog_2/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/deng-2022/blog_2/js/local-search.js" ></script>

  <script defer src="/deng-2022/blog_2/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/deng-2022/blog_2/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
